package com.linkai.多线程._07_gaoji;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: 测试线程池
 * @Author: 林凯
 * @Date: 2021/10/20 0:22
 */
public class TestPool {
    public static void main(String[] args) {
        // 1. 创建服务，创建线程池
        // newFixedThreadPool 参数为：线程池大小
        ExecutorService service = Executors.newFixedThreadPool(10);

        // 执行，将 Runnable 接口的实现类丢进去
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());
        service.execute(new MyThread());

        // 2. 关闭连接
        service.shutdownNow();
    }
}

class MyThread implements Runnable {

    @Override
    public void run() {
            System.out.println(Thread.currentThread().getName());
    }
}
